home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Scheduling / Cassandra / Source / Overview.m < prev    next >
Encoding:
Text File  |  1991-03-12  |  10.6 KB  |  501 lines

  1. //
  2. // Overview.m
  3. // Copyright (c) 1988, 1989, 1990 by Jiro Nakamura 
  4. // All rights reserved
  5. //
  6. // Handles the Overview window for Cassandra
  7. //
  8. //    by Jiro Nakamura (ac6y@vax5.cit.cornell.edu)
  9. //
  10. // RCS Information
  11. // Revision Number->    $Revision: 3.6 $
  12. // Last Revised->    $Date: 90/12/03 01:56:28 $
  13. //
  14. static char rcsid[] = "$Id: Overview.m,v 3.6 90/12/03 01:56:28 jiro Exp Locker: jiro $";
  15.  
  16. #import <appkit/Form.h>
  17. #import <appkit/ScrollView.h>
  18. #import <appkit/Window.h>
  19. #import <appkit/Bitmap.h>    // for Miniworld bitmap
  20. #import <appkit/Panel.h>           // for NXRunAlertPanel 
  21. #import <appkit/Application.h>     // for NX_MODALRESPTHRESHOLD 
  22. #import <appkit/Font.h>        // for Font
  23.  
  24. #import <sys/time.h>        
  25. #import <sys/file.h>
  26. #import <libc.h>
  27. #import <strings.h>
  28.  
  29. #import "Overview.h"
  30. #import "Event.h"
  31. #import "Global.h"
  32. #import "misc.h"
  33. #import "calendar.h"
  34.  
  35. // The font point size of the months
  36. #define FONTNAME_MONTHS    "Courier"
  37. #define FONTSIZE_MONTHS    12.0
  38.  
  39. // The minimum dimensions of the overview window
  40. #define MIN_WIDTH            500.0
  41. #define MIN_HEIGHT            280.0
  42.  
  43. // This function's predeclaration
  44. void showCalendar(  int month, int year, id cal);
  45.  
  46. @implementation Overview
  47. + new
  48. {
  49.  
  50.     #ifdef DEBUG
  51.         fprintf(stderr,"Overview being created.\n");
  52.     #endif
  53.       
  54.     self = [super new];
  55.     [self    setDelegate:self];
  56.     return self;
  57. }
  58.  
  59. - free
  60. {
  61.     [eventText free];
  62.     [super free];
  63.     return nil;
  64. }
  65.  
  66. - open: sender
  67. {
  68.     static alreadyInited = FALSE;
  69.  
  70.     if( !alreadyInited)
  71.         {
  72.         alreadyInited = TRUE;
  73.  
  74.         [self placeWindow: [global overviewFrame]];
  75.         
  76.         showSeconds = [global showSeconds];
  77.         lowPriority  = [global lowPriority];
  78.         militaryTime = [global militaryTime];
  79.  
  80.         [lastMonthText setSelectable:NO];
  81.         [thisMonthText setSelectable:NO];
  82.         [nextMonthText setSelectable:NO];
  83.  
  84.         [thisMonthText    setOpaque:    YES];
  85.         [lastMonthText    setOpaque:    YES];    
  86.         [nextMonthText    setOpaque:    YES];
  87.     
  88.         [thisMonthText    setMonoFont:    NO];
  89.         [lastMonthText    setMonoFont:    NO];    
  90.         [nextMonthText    setMonoFont:    NO];
  91.  
  92.         [thisMonthText    setBackgroundGray:    NX_LTGRAY];
  93.         [lastMonthText    setBackgroundGray:    NX_LTGRAY];
  94.         [nextMonthText    setBackgroundGray:    NX_LTGRAY];
  95.  
  96.         [thisMonthText    setTextGray:    NX_BLACK];
  97.         [lastMonthText    setTextGray:    NX_DKGRAY];
  98.         [nextMonthText    setTextGray:    NX_DKGRAY];
  99.         
  100.         [self windowDidUpdate: self];
  101.         [self setMiniwindowIcon: OVERVIEWICON];
  102.         
  103.         priorityCutOff = [global lowPriority];
  104.         viewPopUp =         [PopUpList new];
  105.         [viewPopUp    addItem:    "View All"];
  106.         [viewPopUp    addItem:    "View Mid~High"];
  107.         [viewPopUp    addItem:    "View Only High"];
  108.         [[viewPopUp itemList] selectCellAt:1:0];
  109.         NXAttachPopUpList(viewPopUpButton, viewPopUp);
  110.         }
  111.         
  112.     [self makeKeyAndOrderFront: sender];
  113.     [self    timeUpdate: self];
  114.     
  115.     [self monthRedraw];
  116.     
  117.     return self;
  118. }
  119.         
  120. - close
  121. {
  122.     [global    saveThisWindowPosition: DEFAULTOVERVIEWFRAME: self];
  123.     [super close];
  124.     return self;
  125. }
  126.  
  127. - printPSCode: sender
  128. {
  129.     [eventText printPSCode: self];
  130.     return self;
  131. }
  132.  
  133. - defaultsDidChange: sender
  134. {
  135.     #ifdef DEBUG
  136.         fprintf(stderr,"Defaults changed.... Overview compensating\n");
  137.     #endif
  138.  
  139.     showSeconds = [global showSeconds];
  140.     
  141.     if( (militaryTime != [global militaryTime]) || 
  142.         (lowPriority  != [global lowPriority]))
  143.         {
  144.         militaryTime = [global militaryTime];
  145.         lowPriority  = [global lowPriority];
  146.         [self queueDidChange: self];
  147.         }
  148.     return self;
  149. }
  150.  
  151. - queueDidChange : sender
  152. {
  153.     #ifdef DEBUG
  154.         fprintf(stderr,"Queue changed.... Overview compensating\n");
  155.     #endif
  156.  
  157.     [self listUpdate:self];
  158.     return self;
  159. }
  160.  
  161. - windowDidUpdate: sender
  162. {
  163.     #ifdef DEBUG
  164.         fprintf(stderr,"Yup, window updated.\n\n");
  165.     #endif
  166.  
  167.     eventText = [eventScroll docView];
  168.     [eventText setFont: 
  169.             [Font newFont:     [global fontName]
  170.                      size:    [global fontSize]]];
  171.     [eventText setEditable: FALSE];
  172.     
  173.     monthNow     = timeNow()->tm_mon;
  174.     yearNow     = timeNow()->tm_year;
  175.     showCalendar( monthNow,     yearNow, thisMonthText);
  176.     showCalendar( monthNow+1,     yearNow, nextMonthText);
  177.     showCalendar( monthNow-1,     yearNow, lastMonthText);
  178.     
  179.     [self listUpdate:self];
  180.     return self;
  181. }
  182.  
  183. - windowWillResize: (id) sender toSize: (NXSize *) size
  184. {
  185.     #ifdef DEBUG
  186.         fprintf(stderr,"Window would have resized to %f x %f.\n", size->width, size->height);
  187.     #endif
  188.     
  189.     if( size->width < MIN_WIDTH)
  190.         size->width = MIN_WIDTH;
  191.     if( size->height < MIN_HEIGHT)
  192.         size->height = MIN_HEIGHT;
  193.         
  194.     #ifdef DEBUG
  195.         fprintf(stderr,"Window will resize to %f x %f.\n", size->width, size->height);
  196.     #endif
  197.     return self;
  198. }
  199.  
  200. // This method updates the event queue as displayed by the
  201. // Overview
  202. - listUpdate: sender
  203. {
  204.     NXStream *output; 
  205.     Event *ev;
  206.     int  today, lastday, temp;
  207.     char annvTemp[30];
  208.     static char *  annv[5] = {"???","days","weeks","months","years"};
  209.     static char *  annv2[5] = {"???","Daily","Weekly","Monthly","Yearly"};
  210.  
  211.  
  212.     // We want to read the eventFile pointed to by global 
  213.     ev = [Event newAt:[global eventFile]];
  214.  
  215.     // We need a temporary memory stream to store the queue.
  216.     if( (output = NXOpenMemory( NULL, 0, NX_READWRITE)) == NULL)
  217.         {
  218.         fprintf(stderr,"%s: Couldn't open memory stream for "
  219.             "Overview queue scrollview. FATAL ERRROR.\n",
  220.             PROGNAME);
  221.         exit(1) ;
  222.         }
  223.                 
  224.     [ev firstEvent];    
  225.     today = [ev mday];
  226.     
  227.     NXPrintf(output, "{\\rtf0\\ansi{\\fonttbl\\f0\\fmodern "
  228.                 "%s;}\\fs%.0f\n",
  229.                 [global fontName], [global fontSize] * 2);
  230.  
  231.     /* Print all events for today regardless of priority, */
  232.     /* today being the */
  233.     /* first day in the event queue */
  234.     
  235.     if( [ev present] == 0)    /* If it is an empty queue */
  236.         NXPrintf(output, "{\\f0 "
  237.                 "----      Empty Event Queue      ----"
  238.                 "\\par}\n");
  239.     else    
  240.         NXPrintf(output,    "{\\f0\\b %s\\par}\n",
  241.             ascMyDate([ev time]));
  242.         
  243.  
  244.     while ( [ev present] != 0 && [ev mday] == today)
  245.         {
  246.         if( [ev anniversary]>0)    /*If there is an anniversary event */
  247.             {
  248.             if( [ev anniversary] % 100 > 1)
  249.                 sprintf(annvTemp, "(Every %d %s)", 
  250.                     [ev anniversary] % 100, 
  251.                     annv[ ( [ev anniversary] / 100) ]);
  252.             else
  253.                 sprintf(annvTemp, "(%s)", 
  254.                     annv2[ ( [ev anniversary] / 100) ]);
  255.             }
  256.         else
  257.             strcpy(annvTemp , "");
  258.             
  259.         if( [ev priority] > [global highPriority])
  260.             NXPrintf(output, "{\\f0\\b ");
  261.         else
  262.             NXPrintf(output, "{\\f0 ");
  263.  
  264.         if( [global militaryTime])
  265.             NXPrintf(output, "  %3d]  %2d:%02d  \t%s"
  266.                     "\t%s\\par}", 
  267.                 [ev present],  
  268.                 [ev hour], [ev min],
  269.                 [ev message], annvTemp);
  270.         else
  271.             {
  272.             temp = [ev hour];
  273.             
  274.             if( temp > 12 )
  275.                 temp -= 12;
  276.             if( temp == 0 )
  277.                 temp = 12;
  278.                 
  279.             NXPrintf(output, "  %3d]  %2d:%02d %s  \t%s"
  280.                     "\t%s\\par}", 
  281.                 [ev present],  
  282.                 temp,
  283.                 [ev min], 
  284.                 ([ev hour]>11)?"pm":"am",
  285.                 [ev message], annvTemp);
  286.             }
  287.  
  288.         [ev readEvent : [ev next]]; 
  289.         }   
  290.     
  291.         
  292.     NXPrintf(output,
  293.         "{\\f0\\par        -----------------------\\par}\n");    
  294.     
  295.     lastday = -1;        // Make it an illegal day value
  296.                         
  297.     /* Print all remaining events according to priority */
  298.     while ( [ev present] != 0)
  299.         {
  300.         // If the priority is high enough 
  301.         // (or if it is the first event), 
  302.         // then we will print this event
  303.         // otherwise we skip it.
  304.         if( [ev priority] < priorityCutOff && [ev previous] != 0)
  305.             {
  306.             #ifdef DEBUG
  307.                 fprintf(stderr,"Skipped %d\n", [ev present]);
  308.             #endif
  309.             [ev readEvent : [ev next]];     
  310.             continue;
  311.             }
  312.         
  313.         // If the event before was not on the
  314.         // same day as the event
  315.         // now, then print a line to space it somewhat
  316.         if( lastday != [ev mday])    
  317.             {
  318.             NXPrintf(output, "{\\f0\\par\\b %s\\par}\n",
  319.                 ascMyDate([ev time]));
  320.             lastday = [ev mday];
  321.             }
  322.                 
  323.         if( [ev anniversary]>0)        // An anniversary event
  324.             {                
  325.             // If it is just a 
  326.             //once every _1_ event then we can print that
  327.             if( [ev anniversary] % 100 > 1)
  328.                 sprintf(annvTemp, "(Every %d %s)",
  329.                 [ev anniversary] % 100, 
  330.                 annv[ ( [ev anniversary] / 100) ] );
  331.             else
  332.                 sprintf(annvTemp, "(%s)", 
  333.                     annv2[ ( [ev anniversary] / 100) ]);
  334.             }
  335.         else
  336.             strcpy(annvTemp , "");
  337.  
  338.         if( [ev priority] > [global highPriority])
  339.             NXPrintf(output, "{\\f0\\b ");
  340.         else
  341.             NXPrintf(output, "{\\f0 ");
  342.     
  343.         if( [global militaryTime])
  344.             NXPrintf(output, 
  345.                 "  %3d]  %2d:%02d  "
  346.                 "\t%s\t%s\\par}", 
  347.                 [ev present], [ev hour], [ev min],
  348.                 [ev message], annvTemp);
  349.         else
  350.             {
  351.             temp = [ev hour];
  352.             
  353.             if( temp > 12 )
  354.                 temp -= 12;
  355.             if( temp == 0 )
  356.                 temp = 12;
  357.                 
  358.             NXPrintf(output, "  %3d]  %2d:%02d %s  \t%s"
  359.                 "\t%s\\par}", 
  360.                 [ev present], temp, [ev min], 
  361.                 ([ev hour]>11)?"pm":"am",
  362.                 [ev message], annvTemp);
  363.             }
  364.             
  365.         [ev readEvent : [ev next]];         
  366.         }   
  367.     
  368.     NXPrintf(output, "}\n");    
  369.     NXSeek(output, 0, NX_FROMSTART);
  370.     [eventText readRichText:output]; 
  371.     [eventText hideCaret];        // for some reason the Text
  372.                     // object sometimes leaves a caret...
  373.  
  374.     NXCloseMemory(output, NX_FREEBUFFER);  
  375.     return self;
  376. }
  377.  
  378. - viewPopUpChanged:sender
  379. {    
  380.     switch( [[viewPopUp itemList] selectedRow])
  381.         {
  382.         case 2:
  383.             priorityCutOff = [global highPriority];
  384.             break;
  385.         case 1:
  386.             priorityCutOff = [global lowPriority];
  387.             break;
  388.         case 0:
  389.         default:
  390.             priorityCutOff = 0;
  391.             break;
  392.         }
  393.     #ifdef DEBUG
  394.         fprintf(stderr, "Priority changed to %d.... (tag = %d)\n",
  395.              priorityCutOff, [[viewPopUp itemList] selectedRow]);
  396.     #endif
  397.     [self listUpdate: self];
  398.     return self;
  399. }
  400.  
  401. - timeUpdate:sender
  402. {    
  403.     if( [self isVisible])
  404.         [dateForm setStringValue : ascMyTime( (struct tm*) timeNow(), 
  405.                 showSeconds, militaryTime) at:0];
  406.  
  407.     return self;
  408. }
  409.         
  410.  
  411. - monthUpdate: sender
  412. {
  413.     monthNow = timeNow()->tm_mon;
  414.     yearNow = timeNow()->tm_year;
  415.     [self monthRedraw];
  416.     return self;
  417. }
  418.  
  419. - monthRedraw
  420. {    
  421.     if( [self isVisible] )
  422.         {
  423.         showCalendar( monthNow,   yearNow, thisMonthText);
  424.         showCalendar( monthNow+1, yearNow, nextMonthText);
  425.         showCalendar( monthNow-1, yearNow, lastMonthText);
  426.         }
  427.     return self;
  428. }
  429.  
  430. - monthPrevious: sender
  431. {
  432.     monthNow --;
  433.     if( monthNow < 0)
  434.         {
  435.         monthNow += 12;
  436.         yearNow --;
  437.         }
  438.     [self monthRedraw];
  439.     return self;
  440. }
  441.  
  442. - monthNext: sender
  443. {
  444.     monthNow ++;
  445.     if( monthNow > 11)
  446.         {
  447.         monthNow -= 12;
  448.         yearNow ++;
  449.         }
  450.     [self monthRedraw];
  451.     return self;
  452. }
  453.  
  454.  
  455. // Procedure:    showCalendar
  456. // Arguments:    month, year; Show the month calendar for this date
  457. //        id cal;        Put it up on this Text view.
  458. // Description:    Writes up a small month calendar for the particular month.
  459. //        If it is this month, bold face (high-light) today.
  460. void showCalendar(int month, int year, id cal)
  461. {
  462.     NXStream    *in; 
  463.     int day;
  464.     
  465.     if( month == timeNow()->tm_mon && year == timeNow() -> tm_year)
  466.         day = timeNow()->tm_mday;
  467.     else
  468.         day = 0;
  469.  
  470.     if( month < 0)
  471.         {
  472.         month = 12;
  473.         year --;
  474.         }
  475.     else
  476.         {
  477.         if( month > 11)
  478.             {
  479.             month = 1;
  480.             year ++;
  481.             }
  482.         else
  483.             month ++;
  484.         }
  485.     #ifdef  DEBUG
  486.         fprintf(stderr,"%s: Opening %d:%d for calendar.\n",
  487.                 PROGNAME, month, year);
  488.     #endif
  489.     
  490.     in = NXOpenMemory(NULL, 0, NX_READWRITE );
  491.     
  492.     printCalendarRTF( day, month, 1900+ year, in,
  493.             FONTNAME_MONTHS, FONTSIZE_MONTHS);
  494.     NXSeek(in, 0, NX_FROMSTART);
  495.     [cal setRetainedWhileDrawing: YES];
  496.     [cal readRichText:in]; 
  497.     NXCloseMemory(in, NX_FREEBUFFER);     
  498. }
  499. @end
  500.  
  501.